package cn.xshi.actuator.jvm;

import cn.xshi.actuator.util.ExecuteCmd;
import cn.xshi.actuator.util.ActuatorSDKUtil;

import java.io.File;

/**
 * @Desc 堆快照
 * @Author 邓纯杰
 * @CreateTime 2013-10-05 17:15:42
 */
public class JMapUtil {
    /**
     * 导出堆快照
     * @return
     */
    public static String dump(){
        String id = ActuatorSDKUtil.getPid();
        String path = ActuatorSDKUtil.getRootPath("dump/"+id+"_heap.hprof");
        File file = new File(ActuatorSDKUtil.getRootPath("dump/"));
        if (!file.exists()){
            file.mkdirs();
        }
        ExecuteCmd.execute(new String[]{"jmap","-dump:format=b,file="+path, id});
        return path;
    }
}
